home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: Using MFC with C
- Date: 30 Jan 1996 03:15:29 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4ek2gh$t26@news1.usa.pipeline.com>
- NNTP-Posting-Host: pipe6.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Jan 29, 1996 19:31:35 in article <Using MFC with C>, 'sean@crl.com (Sean
- Kenefick)' wrote:
-
-
- >I'm a C programmer just now learning C++.
- >
- >I have an exisiting project -- a big one -- that has been written in
- >C. I want to add a new C++ module with a newly created class which
- >uses, but isn't derived from, a couple of MFC classes (CString for
- >example). I *definitely* don't want to rewrite all my C code. Is it
- >possible to call a class' method in a C++ module from an exisiting
- >external C module? How should they be declared? I tried using extern
- >and extern "C" but the compiler just threw it back at me.
- >
- >BTW: I can't put all these things in the same module because "AFX.H"
- >and "WINDOWS.H" conflict with each other. The C code won't compile
- >with the "AFX.H" and vice-versa.
- >
- >Any help would be greatly appreciated.
- >
- There's no (reasonable) way to call C++ class member functions
- directly from C. You need to write an API layer for the C++ module.
- If you're passing pointers to C++ classes to the C side, then you can
- do something like this:
-
- int FooApi (void * object, int arg)
- {
- FooClass * p = (FooClass*)object;
- return p->Foo(arg);
- }
-
- Of course, the two lines can be combined; I just thought it might
- be clearer when split into two.
- >
- --
- Pete Grant
- Kalevi, Inc.
- Object Oriented Software Development
-